/**
 * @author luoqingbo
 * @create 2024/5/8 9:46
 */
public class Leetcode2079 {
    public static void main(String[] args) {
        int[] plants = {2, 2, 3, 3};
        int capacity = 5;
        int ans = wateringPlants(plants, capacity);
        System.out.println(ans);
    }

    public static int wateringPlants(int[] plants, int capacity) {
        int steps = 0;
        int pos = 0;
        int tempCapacity = capacity;
        for (int i = pos; i < plants.length; i++) {
            if (tempCapacity >= plants[i]) {
                tempCapacity -= plants[i];
                steps++;
            } else {
                //回去取水,再回来
                steps += ((2 * i) + 1);
                tempCapacity = capacity - plants[i];
            }
        }
        return steps;
    }
}
